package Controller.User;

import Dto.User;
import Service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "preUpdateLogin", value = "/preUpdateLogin")
public class PreUpdateLogin extends HttpServlet {
    private UserService userService = new UserService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String nickname = request.getParameter("nickname");
        try {
            User user = userService.preUpdateLogin(nickname);
            request.setAttribute("user",user);
            request.getRequestDispatcher("/updatepassword.jsp").forward(request,response);
        }catch (SQLException e){
            System.out.println("sql异常");
            e.printStackTrace();
        }
    }
}
